import { defineStore } from 'pinia'

/**
 * 用户信息数据结构
 */
export type UserStoreInfo = {
  username: string,
  avatar: string
}

/**
 * 用户信息
 */
export const userStore = defineStore('useStore', {
  state: () => {
    return {
      userInfo: {
        username: '',
        avatar: ''
      }
    }
  },
  actions:{
    setUserInfo(data: UserStoreInfo){
      this.userInfo = data
    }
  },
  persist: {
    storage: localStorage
  }
})

/**
 * 登陆token
 */
export const tokenStore = defineStore('tokenStore', {
  state: () => {
    return {
      token: ''
    }
  },
  actions: {
    logout(){
      this.token = ''
    }
  },
  persist: {
    storage: localStorage
  }
})